<template>
    <!-- 理赔详情 -->
    <div class="divBox">
        <el-card class="box-card">
            <div :style="$cssStyle.headLine">
                {{ this.$route.meta.title }}
            </div>
            <Info :info="info" v-loading="loading" :isDisable="true" @complete="submitForm" />
        </el-card>
    </div>
    <!-- 理赔详情 -->
</template>

<script>
import Info from '@/views/components/Info.vue';
export default {
    data() {
        return {
            loading: false,
            isDisable: true,
            info: {},
        }
    },
    components: {
        Info,
    },
    created() {
    this.showInfo();
  },
  methods: {
    //加载公司信息
    async showInfo() {
      try {
        this.loading = true;
        const res = await showInfoApi();
        res.address = [res.provinceId, res.cityId, res.districtId]
        this.info = Object.assign({}, this.info, res);
        this.loading = false;
      } catch (error) {
        this.loading = false
      }

    },

    // 上传图片返回链接
    async questImg(data) {
      for (const key in data) {
        if (data[key] instanceof File) {
          const newFile = await compressorImage(data[key]);
          const formData = new FormData();
          formData.append('model', 'user');
          formData.append('multipart', newFile);
          formData.append('pid', 1);
          const res = await fileImageApi(formData);
          if (res && res.url) {
            data[key] = res.url;
          }
        }
        if (typeof data[key] === 'object') {
          this.questImg(data[key]);
        }
      }
    },

    // 提交资料
    async submitForm(form) {
      this.loading = true;
      try {
        await this.questImg(form);
        await updateInfoApi(form, { type: 0 });
        this.$message.success('提交成功');
        this.isDisable = true;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    }
  }
}
</script>

<style lang="scss" scoped >
.shop-info {
  width: 100%;
  position: relative;

  .update-text {
    display: block;
    position: absolute;
    right: 0;
    top: 0;
  }

  .title {
    text-align: center;
    font-weight: 600;
    font-size: 20px;
  }

  .info {
    padding-left: 30px;
    padding-top: 30px;
    background-color: #fff;
  }

  .link-1 {
    display: flex;

    .el-form-item {
      flex: 1;
    }
  }

  .link-2 {
    width: 600px;
    display: flex;
    justify-content: space-between;
  }
}
</style>